package com.eunion.web.character.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Path;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.domain.Sort.Order;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import com.eunion.web.character.entity.CharacterOption;
import com.eunion.web.character.repository.CharacterOptionRepository;
import com.eunion.web.character.service.CharacterOptionService;
import com.eunion.web.common.base.BaseRepository;
import com.eunion.web.common.base.impl.BaseServiceImpl;

@Service("character_option_service")
public class CharacterOptionServiceImpl extends BaseServiceImpl<CharacterOption, Integer> implements CharacterOptionService{

	@Autowired
	private CharacterOptionRepository respository;

	
	@Override
	public BaseRepository<CharacterOption, Integer> geBaseRepository() {
		// TODO Auto-generated method stub
		return respository;
	}

	@Override
	public List<CharacterOption> findCharacterOptionByTopic(String topicId) {
		// TODO Auto-generated method stub
		//排序查询
		List<Order>orderList=new ArrayList<Order>();
		Order order=new Order(Direction.ASC, "id");
		orderList.add(order);
		Sort sort=new Sort(orderList);
		/*根据条件排序查询*/
		Specification <CharacterOption> specification=new Specification<CharacterOption>() {
			public Predicate toPredicate(Root<CharacterOption> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
				return cb.equal(root.get("topicId"), topicId);
			}
		};
		Pageable pa=new PageRequest(0, 10000, sort);
		Page<CharacterOption> page=findAll(specification, pa);
		//查询出所有的菜单
		List<CharacterOption> list=page.getContent();
		return list;
	}
}
